layui.use(['form'], function () {

    var $ = layui.jquery, layer = layui.layer;

    var form = layui.form
    var disable = false


    //监听提交(新增部门)
    form.on('submit(demo1)', function (data) {
        event.preventDefault();
        if (disable) return
        disable = true
        $.ajax({
            type: "POST",
            url: "/ams-admin/dept/add",
            data: JSON.stringify(data.field),
            contentType: "application/json",
            success: function (r) {
                disable = false
                if(r.code === 0){
                    layer.alert("新增成功！",function (){
                        window.parent.location.reload()
                        parent.layer.close(index)
                    })
                }else {
                    layer.alert(r.msg);
                }
            }
        });
    });
    //表单取值
    layui.$('#LAY-component-form-getval').on('click', function () {
        var data = form.val('example');
        alert(JSON.stringify(data));
    });
});

function load_deptTree() {
    layer.open({
        type: 2
        , title: "选择上级部门" //不显示标题栏
        , closeBtn: 1
        , area: ['350px','400px']
        , shade: 0.8
        , btn: ['确定', '取消']
        , btnAlign: 'c'
        , offset: 'auto'
        , scrollbar: false
        , content: 'dept_tree.html'
    });
}